home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / Files / Education / M / MathPad 2.15 / examples / interpolation < prev    next >
Encoding:
Text File  |  1993-10-06  |  534 b   |  24 lines  |  [TEXT/MPAD]

  1. -- Solve for coefficients of a polynomial that goes through n data points.
  2.  
  3. data = read(xydata)
  4. plot data[1:n]
  5.  
  6. x[i]=data[i,1] dim[n] -- separate x and y
  7. y[i]=data[i,2] dim[n]
  8.  
  9. f(x)[j] = x^(j-1)  -- polynomial
  10.  
  11. -- construct matrix using x data points
  12. A[i,j] = f(x[i])[j] dim[n,n]
  13.  
  14. -- solve for coeffs that give y points
  15. c:=solve(A,y):
  16. c:{0.797,3.863,-0.715,0.057,-0.002,0.000}
  17.  
  18. n=6
  19. plot sum((c*f(X))[i],i,1,n)
  20.  
  21. ----general equation solver
  22. solve(A,B)[j] = det(cram(A,B,j))/det(A)
  23. cram(A,B,k)[i,j] = A[i,j] when j≠k, B[i] dim[count(B)]
  24.